package utils
{
	import flash.filesystem.*;
	import flash.xml.*;
	
	import mx.collections.ArrayCollection;
	import mx.events.FlexEvent;

	public class XMLUtils
	{	
		public static function LoadXMLData():ArrayCollection
		{		
			var resultArray:ArrayCollection = new ArrayCollection();
			
			if (File.applicationDirectory.resolvePath("xml").exists && File.applicationDirectory.resolvePath("xml").isDirectory)
			{
				var dirContent:Array = File.applicationDirectory.resolvePath("xml").getDirectoryListing();
				
				for (var i:Number = 0; i < dirContent.length; i++)
				{
					if (File(dirContent[i]).extension == "xml")
					{	
						var file:File = File.applicationDirectory.resolvePath(File(dirContent[i]).nativePath); 
						var fileStream:FileStream = new FileStream(); 
						fileStream.open(file, FileMode.READ); 
						var xml:XML = XML(fileStream.readUTFBytes(fileStream.bytesAvailable)); 
						fileStream.close(); 
						
						if (xml != null)
						{
							resultArray.addItem(xml);
						}
					}
				}
			}
			
			return resultArray;
		}
	}
}